#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=12;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
char str[maxn];
LL ans=10;
void dfs(LL pos){
     if(pos==11){
        LL win1=0;LL win2=0;
        for(LL i=1;i<=10;i++){
            if(i&1){
                if(str[i]=='1') win1++;
            }
            else if(i%2==0){
                if(str[i]=='1') win2++;
            }
            LL cnt1=0;LL cnt2=0;
            for(LL j=i+1;j<=10;j++){
                if(j&1) cnt1++;
                else cnt2++;
            }
            if(win1+cnt1<win2||win2+cnt2<win1)  ans=min(ans,i);
        }
        return;
     }
     if(str[pos]=='?'){
        str[pos]='1';
        dfs(pos+1);
        str[pos]='0';
        dfs(pos+1);
        str[pos]='?';
     }
     else dfs(pos+1);
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL t;cin>>t;
    while(t--){
        cin>>(str+1);
        ans=10;
        dfs(1);
        cout<<ans<<endl;
    }
   	return 0;
}
